"""
try的使用
try是用来处理异常的
"""

def testTry():
    """
    try的声明形式
    """

    myExc = False

    try:
        # 这里会产生异常，因为变量没有定义
        print(myError)
    except NameError:
        myExc = True
    
    print("after generate exception, myExc is {}".format(myExc))

    # 使用finally
    try:
        print(myError)
    except NameError:
        myExc = False
    finally:
        print("execute finally block")
    
    print("after generate exception again, myExc is {}".format(myExc))

testTry()